package com.dson.filter;

import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.*;


@Activate(group = {CommonConstants.PROVIDER,CommonConstants.CONSUMER})
public class IpTransportFliter implements Filter {

    @Override
    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
        String ip = RpcContext.getContext().getAttachment("IP");
        if(StringUtils.isNoneBlank(ip)){
            System.out.println("当前请求IP："+ip);
        }
        return invoker.invoke(invocation);
    }
}
